package com.apex.system.service.impl;

import com.apex.system.dto.SysUserDto;
import com.apex.system.entity.SysUser;
import com.apex.system.mapper.SysUserMapper;
import com.apex.system.service.SysUserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser > implements SysUserService {

    @Autowired
    SysUserMapper sysUserMapper;

    //查询用户
    @Override
    public SysUserDto getUserInfo(Long userId) {
        SysUser userInfo = this.getById(userId);
        SysUserDto userDto = new SysUserDto();
        BeanUtils.copyProperties(userInfo, userDto, "password");
        return userDto;
    }

    //修改用户信息
    @Override
    public Integer updateUserInfo(SysUserDto sysUserDto) {
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(sysUserDto, sysUser);
        return sysUserMapper.updateById(sysUser);
    }

    //新增用户信息
    @Override
    public Integer addUser(SysUserDto sysUserDto) {
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(sysUserDto, sysUser);
        return sysUserMapper.insert(sysUser);
    }

    @Override
    public Page<SysUserDto> selectAll(Integer currnetPage, Integer pageSize) {
        Page<SysUserDto> page = new Page<>(currnetPage, pageSize);
        return sysUserMapper.selectAll(page);
    }


}
